package demo2;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2024-05-04
 * Time: 17:59
 */
public class Test {
    public static void func() throws ClassNotFoundException {
        Class<?> c1 = Class.forName("demo2.TestEnum");
        try {
            Constructor<?> constructor =
                    c1.getDeclaredConstructor(String.class, int.class, int.class, String.class );
            constructor.setAccessible(true);

            TestEnum testEnum = (TestEnum) constructor.newInstance(6, "棕色");
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) throws ClassNotFoundException {
        func();
        //枚举对象非常安全,就算是通过反射,也不可以创建枚举对象
    }
}
